package lk;

import java.util.ArrayList;
import java.util.List;

public class D230915 {
    // 拥有最多糖果的孩子
    public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        int n = candies.length;
        int max = 0;
        for (int i = 0; i < n; i++) {
            if (max < candies[i]) {
                max = candies[i];
            }
        }
        List<Boolean> res = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if (candies[i] + extraCandies >= max) {
                res.add(true);
            } else {
                res.add(false);
            }
        }
        return res;
    }

    // 拥有最多糖果的孩子
    public boolean canPlaceFlowers(int[] flowerbed, int n) {
        int flg = 0;
        int size = flowerbed.length;
        if (size == 1) {
            if (flowerbed[0] == 0 && n <= 1 || n == 0) {
                return true;
            } else {
                return false;
            }
        }
        if (flowerbed[0] == 0 && flowerbed[1] == 0) {
            flowerbed[0] = 1;
            flg++;
        }
        for (int i = 1; i < size - 1; i++) {
            if (flowerbed[i - 1] == 0 && flowerbed[i] == 0 && flowerbed[i + 1] == 0) {
                flowerbed[i] = 1;
                flg++;
            }
        }
        if (flowerbed[size - 1] == 0 && flowerbed[size - 2] == 0) {
            flowerbed[size - 1] = 1;
            flg++;
        }
        return flg >= n;
    }


    // 反转字符串中的元音字母
    // 双指针, 找左右两边的元音字母, 交换位置
    public String reverseVowels(String s) {
        int n = s.length();
        char[] arr = s.toCharArray();
        int i = 0, j = n - 1;
        while (i < j) {
            while (i < n && !isVowel(arr[i])) {
                ++i;
            }
            while (j > 0 && !isVowel(arr[j])) {
                --j;
            }
            if (i < j) {
                swap(arr, i, j);
                ++i;
                --j;
            }
        }
        return new String(arr);
    }

    public boolean isVowel(char ch) {
        return "aAeEiIoOuU".indexOf(ch) >= 0;
    }

    public void swap(char[] arr, int i, int j) {
        char temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }
}
